package routers

import (
	"github.com/gin-gonic/gin"
	"go-gin-study/pkg/setting"
	v1 "go-gin-study/routers/v1"
)

func InitRouter() *gin.Engine {
	r := gin.New()
	//引用中间件
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	gin.SetMode(setting.RunMode)
	r.GET("/test", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "test",
		})
	})
	apiv1 := r.Group("/api/v1")
	{
		apiv1.GET("/articles", v1.GetArticles)
		apiv1.GET("/articles/:id", v1.GetArticle)
		apiv1.POST("/articles", v1.AddArticle)
		apiv1.DELETE("/articles/:id", v1.DelArticle)
	}
	return r
}
